// https://www.acwing.com/problem/content/829/

#include <iostream>
using namespace std;

constexpr int ARRAY_MAX_SIZE = 100010;

struct ListNode {
    int value;
    int pre_index;
    int next_index;
};

ListNode all_nodes[ARRAY_MAX_SIZE];

int head, tail;

int idx;

int END = -1;

void init() {
    head = 0;
    tail = 1;

    all_nodes[head].pre_index = END;
    all_nodes[head].value = END;
    all_nodes[head].next_index = tail;

    all_nodes[tail].pre_index = head;
    all_nodes[tail].value = END;
    all_nodes[tail].next_index = END;

    // 从第 3 个点开始
    idx = 2;
}

void insert_left(int x) {
    all_nodes[idx].value = x;
    all_nodes[idx].pre_index = head;
    all_nodes[idx].next_index = all_nodes[head].next_index;

    all_nodes[all_nodes[head].next_index].pre_index = idx;
    all_nodes[head].next_index = idx;
    idx++;
}

void insert_right(int x) {
    all_nodes[idx].value = x;
    all_nodes[idx].next_index = tail;
    all_nodes[idx].pre_index = all_nodes[tail].pre_index;

    all_nodes[all_nodes[tail].pre_index].next_index = idx;
    all_nodes[tail].pre_index = idx;
    idx++;
}

void remove_k(int k) {
    all_nodes[all_nodes[k].pre_index].next_index = all_nodes[k].next_index;
    all_nodes[all_nodes[k].next_index].pre_index = all_nodes[k].pre_index;
}

void insert_k_left(int k, int x) {
    all_nodes[idx].value = x;
    all_nodes[idx].next_index = k;
    all_nodes[idx].pre_index = all_nodes[k].pre_index;

    all_nodes[all_nodes[k].pre_index].next_index = idx;
    all_nodes[k].pre_index = idx;
    idx++;
}

void insert_k_right(int k, int x) {
    all_nodes[idx].value = x;
    all_nodes[idx].pre_index = k;
    all_nodes[idx].next_index = all_nodes[k].next_index;

    all_nodes[all_nodes[k].next_index].pre_index = idx;
    all_nodes[k].next_index = idx;
    idx++;
}

int main() {
    int n;
    int k, x;
    char ch;
    cin>>n;
    init();
    while (n-->0) {
        cin>>ch;
        if (ch == 'R') {
            cin>>x;
            insert_right(x);
        } else if (ch == 'L') {
            cin>>x;
            insert_left(x);
        } else if (ch == 'D') {
            cin>>k;
            remove_k(k+1);
        } else if (ch == 'I') {
            char th;
            cin>>th>>k>>x;
            if (th == 'L') {
                insert_k_left(k+1, x);
            } else if (th == 'R') {
                insert_k_right(k+1, x);
            }
        }
    }
    int curr = all_nodes[head].next_index;
    while (curr != END && all_nodes[curr].next_index != END) {
        cout << all_nodes[curr].value << " ";
        curr = all_nodes[curr].next_index;
    }

    return 0;
}
